package com.epwk.action;


import com.epwk.driver.SeleniumDriver;
import com.epwk.element.WebEle;
import com.epwk.logger.LoggerControler;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

/**
 * Created by Administrator on 2016/11/13.
 */
public class AlertAction extends SeleniumDriver {
    final static LoggerControler log= LoggerControler.getLogger(AlertAction.class);


    public static void alert(By by){
        WebEle.findElement(by).click();
        driver.switchTo().alert().accept();
        log.info("在Alert警告框中点击确定按钮");
    }

    public static void confirmAccept(By by){
        WebEle.findElement(by).click();
        Alert confirm = driver.switchTo().alert();
        confirm.accept();
        confirm.dismiss();
        log.info("在confirm警告框中点击确定按钮");
    }

    public static void confirmDismiss(By by){
        WebEle.findElement(by).click();
        Alert confirm = driver.switchTo().alert();
        confirm.dismiss();
        confirm.accept();
        log.info("在confirm警告框中点击取消按钮");
    }

    public static void promptAccept(By by,String concent){
        WebEle.findElement(by).click();
        Alert prompt = driver.switchTo().alert();
        prompt.sendKeys(concent);
        prompt.accept();
        prompt.accept();
        log.info("在prompt中输入"+concent+"后点击确认按钮");
    }

    public static void promptDismiss(By by,String concent){
        WebEle.findElement(by).click();
        Alert prompt = driver.switchTo().alert();
        prompt.sendKeys(concent);
        prompt.dismiss();
        prompt.accept();
        log.info("在prompt中输入"+concent+"后点击取消按钮");
    }
}
